package com.ruoyi.detection.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.detection.domain.Users;
import com.ruoyi.detection.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: base-planthopper-detection-master_202130504106_李航
 * @description:
 * @author: LiHang
 * @create: 2021-09-30 08:31
 **/

@Api("用户登录与账号处理接口")

@Slf4j
@RestController
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 登录
     * @param logininfo
     * @return
     */
    @ApiOperation(value = "登录", notes = "示例:http://192.168.1.217:8989/userLogin\n请求头附带查询条件\n返回查询到的用户列表")
    //@ResponseBody
    @PostMapping("/userLogin")
    public AjaxResult userLogin(Users logininfo){
        List<Users> users = userService.selectUser(logininfo);
        return AjaxResult.success(users);
    }

    /**
     * 注册
     * @param registerInfo
     * @return
     */
    @ApiOperation(value = "注册", notes = "示例:http://192.168.1.217:8989/userRegister\n请求头附带查询条件\n返回查询到的用户列表")
    //@ResponseBody
    @PostMapping("/userRegister")
    public AjaxResult userRegister(Users registerInfo){
        boolean register = userService.register(registerInfo);
        if(register){
            return AjaxResult.success("registerInfo");
        }else {
            return AjaxResult.error("注册失败，手机号已注册");
        }


    }
}
